#ifndef __SHELL_H__
#define __SHELL_H__

/*
 * **********************************************
 * ***           shell.h
 * ***
 * *** Copyright 2007 Ricmar Technology GmbH
 * ***
 * **********************************************
 */


// Qt Includes
#include <QObject>
#include <QString>
#include <QMetaMethod>
#include <QMutex>
#include <QMap>

// Windows Includes


// Linux Includes


// Includes

// Defines


// Prototypes

/**************************************************************************************/

class IShell
    {
    public:
        IShell(QString objName, QObject* obj, bool bGuiContext = false);
        virtual ~IShell();

        void setHelp(const QMap<QString, QString>& help);
        QMap<QString, QString> getHelp() const;

    private:
        QObject* m_pObj;
        QMap<QString, QString> m_help;
    };

/**************************************************************************************/

class IShellObject : public QObject, public IShell
    {
    public:
        IShellObject(QString objName, QObject* obj, bool bGuiContext = false);
        virtual ~IShellObject();
    };

/**************************************************************************************/

class RShell : public QObject
    {
        Q_OBJECT

    public:
        typedef enum
            {
            FAPublicOnly = 0,
            FAAll = 1,
            }FunctionAccess;

    public:
        static RShell* get();

        void registerObject(QObject* obj);
        void unregisterObject(QString objName);

        bool addDataTypeAlias(QString dataType, QString alias);

        QStringList getAvailableClasses();
        QStringList getAvailableObjects(QString className);
        QStringList getAvailableFunctions(QString className, FunctionAccess a = FAPublicOnly);
        QString getParameterNames(QString className, QString funcName);

        bool invokeFunction(QString func);

    signals:
        void shellObjectsChanged();

    private:
        RShell();
        ~RShell();

        QMetaMethod findMethod(QString objName, QString funcName, int nrParams);
        bool invokeFunction(QString objName, QString funcName, QList<const char*> params);

        const char* createParamObject(QString type, QString value);
        void deleteParamObject(char* pData);

    private:
        static RShell* m_pInstance;

        QMap<QString, QObject*> m_ObjMap;
        QMap<QString, QString> m_aliasMap;
        QList<QString> m_supportedParamTypes;
        QMutex m_MapLock;
    };


/**************************************************************************************/


#endif // __SHELL_H__


